package com.yssw.client.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yssw.client.domain.UserServiceLog;
import com.yssw.client.domain.vo.WeChatPaymentVO;
import com.yssw.client.service.WeChatPaymentService;
import com.yssw.common.annotation.Anonymous;
import com.yssw.common.annotation.Log;
import com.yssw.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author KnockingFarmers
 * @Date 2023/4/1 17:16
 * @PackageName:com.yssw.client.controller
 * @ClassName: WeChatPaymentController
 * @Description: TODO
 * @Version 1.0
 */
@Anonymous
@RestController
@RequestMapping("/payment/wechat")
public class WeChatPaymentController {

    @Autowired
    private WeChatPaymentService paymentService;

    /**
     * 唤起支付页面
     */
//    @PreAuthorize("@ss.hasPermi('client:serviceLog:export')")
//    @Log(title = "创建微信支付", businessType = BusinessType.INSERT)
    @PostMapping("/payment")
    public JSONObject payment(@RequestBody WeChatPaymentVO weChatPaymentVO) {
        System.out.println(weChatPaymentVO);
        return paymentService.payment(weChatPaymentVO);
    }


    /**
     * 导出维修记录列表
     */
    @Log(title = "维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserServiceLog userServiceLog) {


//        //查询支付订单
//        QueryOrderByIdRequest queryRequest = new QueryOrderByIdRequest();
//        queryRequest.setMchid("190000****");
//        queryRequest.setTransactionId("4200001569202208304701234567");
//
//        try {
//            Transaction result = service.queryOrderById(queryRequest);
//            System.out.println(result.getTradeState());
//        } catch (ServiceException e) {
//            // API返回失败, 例如ORDER_NOT_EXISTS
//            System.out.printf("code=[%s], message=[%s]\n", e.getErrorCode(), e.getErrorMessage());
//            System.out.printf("reponse body=[%s]\n", e.getResponseBody());
//        }
//
//        //关闭订单
//        CloseOrderRequest closeRequest = new CloseOrderRequest();
//        closeRequest.setMchid("190000****");
//        closeRequest.setOutTradeNo("out_trade_no_001");
//        // 方法没有返回值，意味着成功时API返回204 No Content
//        service.closeOrder(closeRequest);
    }

}
